<%@Page Language="VB" %>
<%@Import Namespace="System.Xml" %>
<%@Import Namespace="System.Xml.Xpath" %>
<html><head>
<title>Searching an XML document with an XPathNavigator</title>
</head>
<body bgcolor="#ffffff">
<span class="heading">Searching an XML document with an XPathNavigator</span><hr />
<div id="outDocURL" runat="server"></div>
<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="vb" runat="server">

Sub Page_Load()


   Dim strCurrentPath As String = Request.PhysicalPath
   Dim strXMLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "booklist.xml"


   Dim objXPathDoc As XPathDocument

   Try


      objXPathDoc = New XPathDocument(strXMLPath)
      outDocURL.innerHTML = "Loaded file: <b>" & strXMLPath & "</b>"

   Catch objError As Exception


      outError.innerHTML = "<b>* Error while accessing document</b>.<br />" _
          & objError.Message & "<br />" & objError.Source
      Exit Sub  ' and stop execution

   End Try


   Dim objXPNav As XPathNavigator = objXPathDoc.CreateNavigator()


   Dim strResults As String = "<b>List of authors</b>:<br />"
   Dim objXPIter As XPathNodeIterator
   objXPIter = objXPNav.Select("descendant::AuthorName")

   Do While objXPIter.MoveNext()


         strResults += objXPIter.Current.Value & "<br />"

   Loop
   outResults.innerHTML = strResults   'display the result
End Sub
</script>
</body>
</html>
